const app = require('../app');
const { NAME_OR_PASSWORD_IS_REQURIED, NAME_IS_ALREADY_EXISTS, NAME_IS_NOT_EXISTS, PASSWORD_IS_INCORRENT, UNAUTHORIZATION, OPERATION_IS_NOT_ALLOWED } = require('../config/error-constants');

app.on('error', (err, ctx) => {
    let code = 0;
    let message = ''
    switch (err) {
        case NAME_OR_PASSWORD_IS_REQURIED:
            code = -10001;
            message = '用户名或密码不能为空！'
            break
        case NAME_IS_ALREADY_EXISTS:
            code = -10002;
            message = '用户名已经存在！'
            break
        case NAME_IS_NOT_EXISTS:
            code = -10003;
            message = '用户名不存在！'
            break
        case PASSWORD_IS_INCORRENT:
            code = -10004;
            message = '输入的密码不正确！'
            break
        case UNAUTHORIZATION:
            code = -10005;
            message = "无效的token或者token已过期~"
            break
        case OPERATION_IS_NOT_ALLOWED:
            code = -20001;
            message = "没有修改权限，不允许的操作~"
            break
        default:
            return
    }

    ctx.body = {
        code,
        message
    }
})


